﻿//-----------------------------------------------------------------------------
// File: VScrollBar.cs
//
// Copyright (c) Dmitry Shuklin. All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;

namespace Cerebrum.Direct3D.Forms.Scrolling
{
    /// <summary>
    /// Элемент управления ScrollBar
    /// </summary>
    public class VScrollBar : Cerebrum.Direct3D.Forms.Control
    {
        public event System.EventHandler ValueChanged;
        public event System.Windows.Forms.ScrollEventHandler Scroll;

        #region Переменные
        private Cerebrum.Direct3D.Forms.ScrollBar liteVScrolBar1;
        private Cerebrum.Direct3D.Forms.ImageButton btnUp;
        private Cerebrum.Direct3D.Forms.ImageButton btnDown;
        private Cerebrum.Direct3D.Forms.ImageButton crawlUp;
        private Cerebrum.Direct3D.Forms.ImageButton crawlDown;
        private Cerebrum.Direct3D.Forms.ImageButton crawlFill;
        private Cerebrum.Direct3D.Forms.Control crawl;
        #endregion

        #region Конструкторы
        /// <summary>
        /// Конструктор класса ScrollBar.
        /// </summary>
        public VScrollBar()
        {
            this.Size = new System.Drawing.SizeF(16, 300);
            // Создаём элементы управления.
            btnUp = new Cerebrum.Direct3D.Forms.ImageButton();
            btnDown = new Cerebrum.Direct3D.Forms.ImageButton();
            liteVScrolBar1 = new ScrollBar();
            crawlUp = new Cerebrum.Direct3D.Forms.ImageButton();
            crawlDown = new Cerebrum.Direct3D.Forms.ImageButton();
            crawlFill = new Cerebrum.Direct3D.Forms.ImageButton();
            crawl = new Control();
            // Настройки кнопки Up.
            btnUp.Dock = System.Windows.Forms.DockStyle.Top;
            btnUp.Location = new System.Drawing.PointF(0, 0);
            btnUp.Size = new System.Drawing.SizeF(this.Size.Width, 16);
            btnUp.MouseDown += new System.Windows.Forms.MouseEventHandler(btnUp_MouseDown);
            btnUp.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.btnUp.ToBitmap();
            // Настройки кнопки Down.
            btnDown.Dock = System.Windows.Forms.DockStyle.Bottom;
            btnDown.Size = new System.Drawing.SizeF(this.Size.Width, 16);
            btnDown.Location = new System.Drawing.PointF(0, this.Size.Height - btnDown.Size.Height);
            btnDown.MouseDown += new System.Windows.Forms.MouseEventHandler(btnDown_MouseDown);
            btnDown.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.btnDown.ToBitmap();
            // Настраиваем ползунок.
            liteVScrolBar1.Dock = System.Windows.Forms.DockStyle.Fill;
            liteVScrolBar1.Location = new System.Drawing.PointF(0, btnUp.Size.Height);
            liteVScrolBar1.SizableCrawler = true;
            liteVScrolBar1.ValueChanged += new EventHandler(liteVScrolBar1_ValueChanged);
            liteVScrolBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(liteVScrolBar1_Scroll);
            // Настраиваем ползунок.
            crawlUp.Dock = System.Windows.Forms.DockStyle.Top;
            crawlUp.Location = new System.Drawing.PointF(0, 0);
            crawlUp.Size = new System.Drawing.SizeF(16, 3);
            crawlUp.Transparent = true;
            crawlUp.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlUp.ToBitmap();

            crawlDown.Dock = System.Windows.Forms.DockStyle.Bottom;
            crawlDown.Location = new System.Drawing.PointF(0, 0);
            crawlDown.Size = new System.Drawing.SizeF(16, 3);
            crawlDown.Transparent = true;
            crawlDown.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlDown.ToBitmap();

            crawlFill.Dock = System.Windows.Forms.DockStyle.Fill;
            crawlFill.Location = new System.Drawing.PointF(0, 0);
            crawlFill.Size = new System.Drawing.SizeF(16, 3);
            crawlFill.Transparent = true;
            crawlFill.NormalLeaveImage = ObjectiveDraw.Platform.Controls.Resource1.CrawlVFill.ToBitmap();

            crawl.Controls.Add(crawlFill);
            crawl.Controls.Add(crawlDown);
            crawl.Controls.Add(crawlUp);

            liteVScrolBar1.CrawlerControl = crawl;
            // Добавляем их на VScrollBar.
            this.Controls.Add(liteVScrolBar1);
            this.Controls.Add(btnDown);
            this.Controls.Add(btnUp);
        }
        #endregion

        #region Обработчики событий
        /// <summary>
        /// Обработчик события нажатия кнопки для перемещения на строку вверх на ScrollBar-е.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDown_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            liteVScrolBar1.ButtonClick(ScrollBarButtons.SmallIncrement);
        }

        /// <summary>
        /// Обработчик события нажатия кнопки для перемещения на строку вниз на ScrollBar-е.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUp_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            liteVScrolBar1.ButtonClick(ScrollBarButtons.SmallDecrement);
        }

        /// <summary>
        /// Передаём событие дальше.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void liteVScrolBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
        {
            if (Scroll != null)
            {
                Scroll(this, e);
            }
        }

        /// <summary>
        /// Передаём событие дальше.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void liteVScrolBar1_ValueChanged(object sender, EventArgs e)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, e);
            }
        }
        #endregion

        #region Интерфейс
        /// <summary>
        /// Нажатие кнопки.
        /// </summary>
        /// <param name="btn">Какая кнопка нажимается.</param>
        public void ButtonClick(ScrollBarButtons btn)
        {
            liteVScrolBar1.ButtonClick(btn);
        }

        /// <summary>
        /// Начальное значение шкалы.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Начальное значение шкалы")
        ]
        public float Minimum
        {
            set
            {
                liteVScrolBar1.Minimum = value;
            }
            get
            {
                return liteVScrolBar1.Minimum;
            }
        }

        /// <summary>
        /// Конечное значение шкалы.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(1000),
            Description("Конечное значение шкалы")
        ]
        public float Maximum
        {
            set
            {
                liteVScrolBar1.Maximum = value;
            }
            get
            {
                return liteVScrolBar1.Maximum;
            }
        }

        /// <summary>
        /// Минимальное перемещение ползунка.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(10),
            Description("Минимальное перемещение ползунка")
        ]
        public float SmallChange
        {
            set
            {
                liteVScrolBar1.SmallChange = value;
            }
            get
            {
                return liteVScrolBar1.SmallChange;
            }
        }

        /// <summary>
        /// Максимальное перемещение ползунка.
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(100),
            Description("Максимальное перемещение ползунка")
        ]
        public float LargeChange
        {
            set
            {
                liteVScrolBar1.LargeChange = value;
            }
            get
            {
                return liteVScrolBar1.LargeChange;
            }
        }

        /// <summary>
        /// Значение (позиция).
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Значение (позиция)")
        ]
        public float Value
        {
            set
            {
                liteVScrolBar1.Value = value;
            }
            get
            {
                return liteVScrolBar1.Value;
            }
        }

        /// <summary>
        /// Вариант возвращения значения в свойстве Value
        /// </summary>
        [
            Category("ScrollBar Settings"),
            DefaultValue(0),
            Description("Вариант возвращения значения в свойстве Value")
        ]
        public Cerebrum.Direct3D.Forms.ScrollingMethodEnum MathMethod
        {
            set
            {
				liteVScrolBar1.ScrollingMethod = value;
            }
            get
            {
				return liteVScrolBar1.ScrollingMethod;
            }
        }

        /// <summary>
        /// Длина прокрутки ползунка.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Длина прокрутки ползунка")
        ]
        public float ScrollBarPathLength
        {
            get
            {
                return liteVScrolBar1.ScrollBarPathLength;
            }
        }

        /// <summary>
        /// Длина ползунка.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Длина ползунка")
        ]
        public float CrawlLength
        {
            get
            {
                return liteVScrolBar1.CurrentCrawlerLength;
            }
        }

        /// <summary>
        /// Элемент управления - ползунок.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Элемент управления - ползунок")
        ]
        public Cerebrum.Direct3D.Forms.Control CrawlControl
        {
            get
            {
                return liteVScrolBar1.CrawlerControl;
            }
        }

        /// <summary>
        /// Кнопка Up.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Кнопка Up")
        ]
        public Cerebrum.Direct3D.Forms.ImageButton UpButton
        {
            get
            {
                return btnUp;
            }
        }

        /// <summary>
        /// Кнопка Down.
        /// </summary>
        [
            Category("ScrollBar info"),
            Description("Кнопка Down")
        ]
        public Cerebrum.Direct3D.Forms.ImageButton DownButton
        {
            get
            {
                return btnDown;
            }
        }
        #endregion
    }
}
